﻿using AppService.IService.Exception;
using AppService.IService.System_setting;
using Domain.Entity.Basic_information;
using Domain.Entity.Exception;
using Domain.Entity.System_operation;
using Domain.Entity.System_Ordermanagement;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.NetworkInformation;
using System.Reflection.Metadata.Ecma335;
using System.Threading;

namespace WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ExceController : ControllerBase
    {

        public IExceService exceService { get; set; }

        [HttpGet("{currentPage},{pageSize}")]
        public IActionResult GetExce(int status, int state, string? event1, string? event2, string? m_time1, string? m_time2, string? cname, int currentPage, int pageSize)
        {
            List<Exception_log> exception_Logs = exceService.GetExce(status, state, event1, event2, m_time1, m_time2, cname, currentPage, pageSize);

            if(exception_Logs != null)
            {
                List<Wb_meter> wb_Meters = exceService.Getwb_Meters(status, state, event1, event2, m_time1, m_time2, cname,currentPage, pageSize);

                List<Orders> orders = exceService.GetOrders(status, state, event1, event2, m_time1, m_time2 , cname, currentPage, pageSize);

                List<Drivers_ment> drivers = exceService.GetDrivers(status, state, event1, event2, m_time1, m_time2, cname, currentPage, pageSize);

                List<Vehicles_ment> vehicles = exceService.GetVehicles(status, state, event1, event2, m_time1, m_time2, cname, currentPage, pageSize);

                List<Carrier_ment> carrier = exceService.GetCarriers(status, state, event1, event2, m_time1, m_time2, cname, currentPage, pageSize);

                return Ok(new { message = "查询成功", exception_Logs, wb_Meters, orders, drivers, vehicles, carrier });
            }
            return Ok(new { message = "查询失败", exception_Logs = "", wb_Meters = "", orders = "", drivers = "", vehicles = "", carrier = "" });
        }

        [HttpGet]
        public IActionResult GetCount(int status, int state, string? event1, string? event2, string? m_time1, string? m_time2, string? cname)
        {
            int count = exceService.GetCount(status, state, event1, event2, m_time1, m_time2, cname);
            return Ok(count);
        }

        [HttpGet]
        public IActionResult GetWb_id()
        {
            List<Wb_meter> wb_Meters = exceService.GetWb_id();
            return Ok(wb_Meters);
        }

        [HttpPost("register")]
        public IActionResult AddExce([FromBody] Exception_log exception)
        {
            bool flag = exceService.AddExce(exception);
            return Ok(flag);
        }

        [HttpGet("{id}")]
        public IActionResult GetException(int id)
        {
            Exception_log exception_Log = exceService.GetException(id);
            return Ok(exception_Log);
        }

        [HttpPut("register")]
        public IActionResult EditExce([FromBody] Exception_log? exception)
        {
            bool flag = exceService.EditExce(exception);
            return Ok(flag);
        }

        [HttpPut("register")]
        public IActionResult ClExce([FromBody] Exception_log? exception)
        {
            bool flag = exceService.ClExce(exception);
            return Ok(flag);
        }

        [HttpPut("{id}")]
        public IActionResult WcExce(int id)
        {
            bool flag = exceService.WcExce(id);
            return Ok(flag);
        }

        [HttpDelete("{id}")]
        public IActionResult DelExce(int id)
        {
            bool flag = exceService.DelExce(id);
            return Ok(flag);
        }

    }
}
